//
//  HHFormLableCell.m
//  HHFormSDK
//
//  Created by Basic on 2018/12/13.
//

#import "HHFormLableCell.h"
#import "HHFormSDKPublic.h"

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wstrict-prototypes"
#import <Masonry/Masonry.h>
#pragma clang diagnostic pop


@interface HHFormLableCell()
@property (nonatomic, strong) UILabel *textLb;
@end



@implementation HHFormLableCell
#pragma mark - system
+ (void)load
{
    [XLFormViewController.cellClassesForRowDescriptorTypes setObject:[self class] forKey:HHFormRowDescriptorTypeLable];
}

#pragma mark - getter
- (UILabel *)textLb {
    if (!_textLb) {
        _textLb = [[UILabel alloc] init];
        _textLb.font = BCComConfig.config.bcBoldFont(15);
        _textLb.textColor = BCComConfig.config.blackColor;
    }
    return _textLb;
}

#pragma mark - XLFormDescriptorCell

+ (CGFloat)formDescriptorCellHeightForRowDescriptor:(XLFormRowDescriptor *)rowDescriptor
{
    return 48;
}
-(void)configure
{
    [super configure];
    [self setSelectionStyle:UITableViewCellSelectionStyleNone];
    [self.contentView addSubview:self.textLb];
    [self.textLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.centerY.mas_equalTo(self.contentView);
    }];
    [self.contentView addSubview:self.asteriskLab];
    [self.asteriskLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.textLb.mas_left).mas_offset(-1);
        make.centerY.mas_equalTo(self.contentView);
    }];
}
-(void)update
{
    [super update];
    self.accessoryType = UITableViewCellAccessoryNone;
    self.asteriskLab.hidden = !self.rowDescriptor.required;
    if (self.rowDescriptor.titleFont) {
        self.textLb.font = self.rowDescriptor.titleFont;
    }
    if (self.rowDescriptor.titleColor) {
        self.textLb.textColor = self.rowDescriptor.titleColor;
    }
    if (self.rowDescriptor.titleLeft>0) {
        [self.textLb mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.rowDescriptor.titleLeft);
        }];
    }
    self.textLb.text = self.rowDescriptor.title;
}
-(BOOL)showBottomSplitLine {
    return YES;
}
@end
